package com.xbongbong.saas.enums.business;

import com.alibaba.fastjson.JSONObject;
import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.paas.enums.FieldTypeEnum;
import com.xbongbong.paas.enums.ScreenTypeEnum;
import com.xbongbong.pro.constant.CommonConstant;
import com.xbongbong.pro.constant.I18nStringConstant;
import com.xbongbong.pro.enums.PaasStageEnum;
import com.xbongbong.pro.statistic.enums.IndicatorRuleEnum;
import com.xbongbong.saas.enums.SetTypeEnum;
import com.xbongbong.saas.enums.ShowTypeEnum;
import com.xbongbong.saas.enums.base.ManagementBaseEnum;
import lombok.Getter;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

/**
 * 客户枚举
 *
 * @author feng.zheng
 * @version v1.0
 * @date 2019/1/18 19:31
 * @since v1.0
 */
@Getter
public enum CustomerManagementEnum {
    // 模板设置界面展示字段  text_26 num_4 file_2 subForm_2 other_4 array_1 date_4 address_1
    /**
     * 基础信息
     * other_1
     */
    BASE_INFO(ManagementBaseEnum.BASE_INFO.getAttr(), "enum.customerManagement.attrName.base_info", "baseInfo", FieldTypeEnum.SEPARATOR.getType(), SetTypeEnum.DISABLE_REPEAT.getCode(), 1, 0, ShowTypeEnum.EDIT_DETAIL.getCode(), 10000, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    //评分字段,分数值(冗余字段（1）num型：61~80; num_61)
    SCORE("num_61", "enum.customerManagement.attrName.attrName.score", "score", FieldTypeEnum.NUM.getType(), 1, 0, 1, ShowTypeEnum.LIST_DETAIL.getCode(), 9995, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    /**
     * 客户名称
     * text_1
     */
    NAME(ManagementBaseEnum.NAME.getAttr(), "enum.customerManagement.attrName.name", "name", FieldTypeEnum.TEXT.getType(), SetTypeEnum.DISABLE_OPEN.getCode(), 0, 0, ShowTypeEnum.ALL.getCode(), 9990, 1, 1, ScreenTypeEnum.SCREEN_GROUP.getType()),
    /**
     * 主联系人名称
     */
    CONTACT_NAME("text_12", "enum.customerManagement.attrName.contact_name", "contactName", FieldTypeEnum.TEXT.getType(), 1, 0, 1, ShowTypeEnum.LIST.getCode(), 9980, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    /**
     * 主联系人电话
     * 仅仅用于前端展示，不存储数据 饶龙&郑风    从es映射中去除 梁鲁江  2020年9月21日11:21:11
     */
    CONTACT_PHONE("subForm_2", "enum.customerManagement.attrName.contact_phone", "contactPhone", FieldTypeEnum.CONTACT_NUMBER.getType(), 3, 0, 1, ShowTypeEnum.LIST.getCode(), 9970, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    /**
     * 上级客户
     */
    PARENT("text_17", "enum.customerManagement.attrName.parent", "parent", FieldTypeEnum.LINK_BUSINESS_SINGLE.getType(), 3, 0, 0, ShowTypeEnum.ALL.getCode(), 9960, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    /**
     * 客户简称
     * text_2
     */
    NAME_SHORT(ManagementBaseEnum.NAME_SHORT.getAttr(), "enum.customerManagement.attrName.name_short", "nameShort", FieldTypeEnum.TEXT.getType(), SetTypeEnum.DISABLE_NONE.getCode(), 0, 0, ShowTypeEnum.ALL.getCode(), 9950, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    /**
     * 客户电话
     * subForm_1
     */
    PHONE(ManagementBaseEnum.PHONE.getAttr(), "enum.customerManagement.attrName.phone", "phone", FieldTypeEnum.CONTACT_NUMBER.getType(), 3, 0, 0, ShowTypeEnum.ALL.getCode(), 9940, 1, 1, ScreenTypeEnum.SCREEN_SEARCH.getType()),
    /**
     * 客户地址
     * address_1
     */
    ADDRESS(ManagementBaseEnum.ADDRESS.getAttr(), "enum.customerManagement.attrName.address", "address", FieldTypeEnum.ADDRESS.getType(), 3, 0, 0, ShowTypeEnum.ALL.getCode(), 9930, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    /**
     * 客户状态
     */
    TYPE("text_4", "enum.customerManagement.attrName.type", "type", FieldTypeEnum.COMBO.getType(), 3, 0, 0, ShowTypeEnum.ALL.getCode(), 9920, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    /**
     * 客户阶段
     */
    CUSTOMER_STAGE("text_18", "enum.customerManagement.attrName.customer_stage", "customerStage", FieldTypeEnum.STAGE_THRUSTER.getType(), 3, 1, 0, ShowTypeEnum.ALL.getCode(), 9910, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    /**
     * 流失原因
     */
    WASTAGE("text_19", "enum.customerManagement.attrName.wastage", "wastage", FieldTypeEnum.COMBO.getType(), SetTypeEnum.DISABLE_NONE.getCode(), 1, 0, ShowTypeEnum.EDIT_DETAIL.getCode(), 9900, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    /**
     * 流失备注
     */
    WASTAGE_MEMO("text_22", "enum.customerManagement.attrName.wastage_memo", "wastageMemo", FieldTypeEnum.TEXTAREA.getType(), SetTypeEnum.DISABLE_NONE.getCode(), 1, 0, ShowTypeEnum.EDIT_DETAIL.getCode(), 9895, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    /**
     * 负责人
     * ownerId
     */
    OWNER_ID(ManagementBaseEnum.OWNER_ID.getAttr(), "enum.customerManagement.attrName.owner_id", "ownerId", FieldTypeEnum.OWNERID.getType(), 1, 1, 0, ShowTypeEnum.ALL.getCode(), 9890, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    /**
     * 协同人
     * coUserId
     */
    COUSERID(ManagementBaseEnum.COUSERID.getAttr(), "enum.customerManagement.attrName.couserid", "coUserId", FieldTypeEnum.COUSERID.getType(), 1, 1, 0, ShowTypeEnum.ALL.getCode(), 9880, 1, 0, ScreenTypeEnum.SCREEN_SEARCH.getType()),
    /**
     * 性别
     */
    SEX("text_23", "enum.customerManagement.attrName.sex", "sex", FieldTypeEnum.COMBO.getType(), 3, 0, 0, ShowTypeEnum.ALL.getCode(), 9870, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    /**
     * 客户生日
     */
    BIRTHDAY("text_21", "enum.customerManagement.attrName.birthday", "birthday", FieldTypeEnum.BIRTHDAY.getType(), 3, 0, 0, ShowTypeEnum.ALL.getCode(), 9860, 1, 0, ScreenTypeEnum.SCREEN_SHOW.getType()),
    /**
     * QQ
     */
    QQ("text_24", "QQ", "qq", FieldTypeEnum.TEXT.getType(), SetTypeEnum.DISABLE_NONE.getCode(), 0, 0, ShowTypeEnum.ALL.getCode(), 9850, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    /**
     * 微信
     */
    WE_CHRT("text_25", "enum.customerManagement.attrName.we_chrt", "weChat", FieldTypeEnum.TEXT.getType(), SetTypeEnum.DISABLE_NONE.getCode(), 0, 0, ShowTypeEnum.ALL.getCode(), 9840, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),

    /**
     * 关联信息
     * other_2
     */
    ASSOCIATED_INFO(ManagementBaseEnum.ASSOCIATED_INFO.getAttr(), "enum.customerManagement.attrName.associated_info", "associatedInfo", FieldTypeEnum.SEPARATOR.getType(), SetTypeEnum.DISABLE_REPEAT.getCode(), 1, 0, ShowTypeEnum.EDIT_DETAIL.getCode(), 9830, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    /**
     * 添加联系人
     * array_1
     */
    ADD_CONTACT(ManagementBaseEnum.ADD_CONTACT.getAttr(), "enum.customerManagement.attrName.add_contact", "addContact", FieldTypeEnum.LINK_FORM.getType(), 3, 1, 0, ShowTypeEnum.EDIT.getCode(), 9820, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType()),

    /**
     * 扩展信息
     * other_3
     */
    EXTEND_INFO(ManagementBaseEnum.EXTEND_INFO.getAttr(), "enum.customerManagement.attrName.extend_info", "extendInfo", FieldTypeEnum.SEPARATOR.getType(), SetTypeEnum.DISABLE_REPEAT.getCode(), 1, 0, ShowTypeEnum.EDIT_DETAIL.getCode(), 9810, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    /**
     * 客户类型
     */
    GENRE("text_3", "enum.customerManagement.attrName.genre", "genre", FieldTypeEnum.COMBO.getType(), 3, 0, 0, ShowTypeEnum.ALL.getCode(), 9800, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    /**
     * 客户性质
     */
    IS_INDIVIDUAL("text_5", "enum.customerManagement.attrName.is_individual", "isIndividual", FieldTypeEnum.COMBO.getType(), 3, 0, 0, ShowTypeEnum.ALL.getCode(), 9790, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    /**
     * 客户分级
     * text_6
     */
    SCALE(ManagementBaseEnum.SCALE.getAttr(), "enum.customerManagement.attrName.scale", "scale", FieldTypeEnum.COMBO.getType(), 3, 0, 0, ShowTypeEnum.ALL.getCode(), 9780, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    /**
     * 客户行业
     */
    INDUSTRY("text_7", "enum.customerManagement.attrName.industry", "industry", FieldTypeEnum.COMBO.getType(), 3, 0, 0, ShowTypeEnum.ALL.getCode(), 9770, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    /**
     * 重要程度
     */
    IMPORTANT_DEGREE("num_1", "enum.customerManagement.attrName.important_degree", "importantDegree", FieldTypeEnum.STAR.getType(), 3, 0, 0, ShowTypeEnum.ALL.getCode(), 9760, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    /**
     * 客户来源
     * text_9
     */
    SOURCE(ManagementBaseEnum.SOURCE.getAttr(), "enum.customerManagement.attrName.source", "source", FieldTypeEnum.COMBO.getType(), 3, 0, 0, ShowTypeEnum.ALL.getCode(), 9750, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    /**
     * 客户官网
     */
    WEBSITE("text_10", "enum.customerManagement.attrName.website", "website", FieldTypeEnum.TEXT.getType(), 3, 0, 0, ShowTypeEnum.ALL.getCode(), 9740, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    /**
     * 客户简介
     */
    INSTRUCTION("text_11", "enum.customerManagement.attrName.instruction", "instruction", FieldTypeEnum.TEXT.getType(), 3, 0, 0, ShowTypeEnum.ALL.getCode(), 9730, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    /**
     * 国家
     */
    COUNTRY("text_8", "enum.customerManagement.attrName.country", "country", FieldTypeEnum.COMBO.getType(), 3, 0, 0, ShowTypeEnum.ALL.getCode(), 9720, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    /**
     * 爱好
     */
    HOBBIES("text_26", "enum.customerManagement.attrName.hobbies", "hobbies", FieldTypeEnum.TEXT.getType(), SetTypeEnum.DISABLE_NONE.getCode(), 0, 0, ShowTypeEnum.ALL.getCode(), 9710, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    /**
     * 图片
     */
    IMAGE("file_1", "enum.customerManagement.attrName.image", "image", FieldTypeEnum.IMAGE.getType(), SetTypeEnum.DISABLE_REPEAT.getCode(), 1, 0, ShowTypeEnum.ALL.getCode(), 9700, 1, 0, ScreenTypeEnum.SCREEN_SHOW.getType()),
    /**
     * 文件
     */
    FILE("file_2", "enum.customerManagement.attrName.file", "file", FieldTypeEnum.UPLOAD.getType(), SetTypeEnum.DISABLE_REPEAT.getCode(), 1, 0, ShowTypeEnum.ALL.getCode(), 9690, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    /**
     * 备注
     */
    MEMO("text_13", "enum.customerManagement.attrName.memo", "memo", FieldTypeEnum.TEXTAREA.getType(), SetTypeEnum.DISABLE_REPEAT.getCode(), 1, 0, ShowTypeEnum.ALL.getCode(), 9680, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    LABEL("array_31", "enum.customerManagement.attrName.label", "label", FieldTypeEnum.LABEL.getType(), SetTypeEnum.DISABLE_REPEAT.getCode(), 1, 0, ShowTypeEnum.ALL.getCode(), 9720, 1, 0, ScreenTypeEnum.SCREEN_SEARCH.getType()),

    /**
     * 系统信息
     * other_4
     */
    SYSTEM_INFO(ManagementBaseEnum.SYSTEM_INFO.getAttr(), "enum.customerManagement.attrName.system_info", "systemInfo", FieldTypeEnum.SEPARATOR.getType(), SetTypeEnum.DISABLE_REPEAT.getCode(), 1, 0, ShowTypeEnum.EDIT_DETAIL.getCode(), 9670, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    /**
     * 创建人
     */
    CREATOR("text_16", "enum.customerManagement.attrName.creator", "creator", FieldTypeEnum.USER.getType(), 1, 0, 0, ShowTypeEnum.ALL.getCode(), 9660, 1, 1, ScreenTypeEnum.SCREEN_GROUP.getType()),
    /**
     * 创建时间
     * addTime
     */
    ADD_TIME(ManagementBaseEnum.ADD_TIME.getAttr(), "enum.customerManagement.attrName.add_time", "addTime", FieldTypeEnum.ADDTIME.getType(), 1, 1, 0, ShowTypeEnum.ALL.getCode(), 9650, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    /**
     * 更新时间
     * updateTime
     */
    UPDATE_TIME(ManagementBaseEnum.UPDATE_TIME.getAttr(), "enum.customerManagement.attrName.update_time", "updateTime", FieldTypeEnum.UPDATETIME.getType(), 1, 1, 0, ShowTypeEnum.ALL.getCode(), 9640, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),

    // 不在模板设置界面展示字段，但需要在列表详情展示
    /**
     * 最后跟进时间
     * date_2
     */
    LAST_CONNECT_TIME(ManagementBaseEnum.LAST_CONNECT_TIME.getAttr(), "enum.customerManagement.attrName.last_connect_time", "lastConnectTime", FieldTypeEnum.DATETIME.getType(), 1, 1, 0, ShowTypeEnum.ALL.getCode(), 9630, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    /**
     * 公海退回时间
     */
    BACK_PUBLIC_DATE("date_3", "enum.customerManagement.attrName.back_public_date", "backPublicDate", FieldTypeEnum.DATETIME.getType(), 1, 1, 1, ShowTypeEnum.LIST.getCode(), 9620, 1, 1, ScreenTypeEnum.SCREEN_GROUP.getType()),
    /**
     * 分配时间
     * date_4
     */
    DISTRIBUTION_DATE(ManagementBaseEnum.DISTRIBUTION_DATE.getAttr(), "enum.customerManagement.attrName.distribution_date", "distributionDate", FieldTypeEnum.DATETIME.getType(), 1, 1, 1, ShowTypeEnum.LIST.getCode(), 9610, 1, 1, ScreenTypeEnum.SCREEN_GROUP.getType()),

    // 逻辑字段
    /**
     * 逻辑创建人
     * creatorId
     */
    CREATOR_ID(ManagementBaseEnum.CREATOR_ID.getAttr(), "enum.customerManagement.attrName.creator_id", "creatorId", FieldTypeEnum.CREATORID.getType(), 1, 0, 1, ShowTypeEnum.NONE.getCode(), 9600, 1, 1, ScreenTypeEnum.SCREEN_OFF.getType()),
    /**
     * 关联生日隐藏
     * num_2
     */
    BIRTHDAY_FLAG(ManagementBaseEnum.BIRTHDAY_FLAG.getAttr(), "enum.customerManagement.attrName.birthday_flag", "birthdayFlag", FieldTypeEnum.NUM.getType(), 1, 0, 1, ShowTypeEnum.NONE.getCode(), 9590, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    /**
     * 月日生日
     * text_15
     */
    BIRTHDAY_MMDD(ManagementBaseEnum.BIRTHDAY_MMDD.getAttr(), "enum.customerManagement.attrName.birthday_mmdd", "birthdayMmdd", FieldTypeEnum.TEXT.getType(), 1, 0, 1, ShowTypeEnum.NONE.getCode(), 9580, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    /**
     * 是否公海
     * num_3
     */
    IS_PUBLIC(ManagementBaseEnum.IS_PUBLIC.getAttr(), "enum.customerManagement.attrName.is_public", "isPublic", FieldTypeEnum.COMBO_NUM.getType(), 1, 0, 1, ShowTypeEnum.NONE.getCode(), 9570, 1, 1, ScreenTypeEnum.SCREEN_GROUP.getType()),
    /**
     * 是否归档
     * num_4
     */
      IS_ARCHIVED(ManagementBaseEnum.IS_ARCHIVED.getAttr(), "enum.customerManagement.attrName.is_archived", "isArchived", FieldTypeEnum.COMBO_NUM.getType(), 1, 0, 1, ShowTypeEnum.NONE.getCode(), 9560, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    /**
     * 钉钉客户id
     * text_14
     */
    DD_CUSTOMER_ID(ManagementBaseEnum.DD_CUSTOMER_ID.getAttr(), "enum.customerManagement.attrName.dd_customer_id", "ddCustomerId", FieldTypeEnum.TEXT.getType(), 1, 1, 1, ShowTypeEnum.NONE.getCode(), 9550, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    /**
     * 上级客户隐藏
     * text_20
     */
    PARENT_HIDE(ManagementBaseEnum.PARENT_HIDE.getAttr(), "enum.customerManagement.attrName.parent_hide", "parentHide", FieldTypeEnum.TEXT.getType(), 3, 0, 1, ShowTypeEnum.NONE.getCode(), 9540, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    /**
     * 栗子公司ID
     * text_66
     */
    CLUE_COMPANY_ID(ManagementBaseEnum.CLUE_COMPANY_ID.getAttr(), "enum.customerManagement.attrName.clue_company_id", "clueCompanyID", FieldTypeEnum.TEXT.getType(), 1, 0, 1, ShowTypeEnum.NONE.getCode(), 9530, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    /**
     * text_83：应收账期
     */
    RECEIVABLE_PERIOD(ManagementBaseEnum.RECEIVABLE_PERIOD.getAttr(), "enum.customerManagement.attrName.receivable_period", "receivablePeriod", FieldTypeEnum.ACCOUNT_PERIOD.getType(), 3, 1, 0, ShowTypeEnum.ALL.getCode(), 9520, 1, 1, ScreenTypeEnum.SCREEN_SHOW.getType()),

    // 关联销售线索字段
    CLUE_ID("text_81", "enum.customerManagement.attrName.clue_id", "clueId", FieldTypeEnum.LINK_BUSINESS_MULTI.getType(), 1, 0, 0, ShowTypeEnum.LIST_DETAIL.getCode(), 9970, 1, 0, ScreenTypeEnum.SCREEN_SEARCH.getType()),
    CLUE_NAME_ID("text_82", "enum.customerManagement.attrName.attrName.clue_name", "clueName", FieldTypeEnum.TEXT.getType(), 1, 0, 1, ShowTypeEnum.NONE.getCode(), 9770, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType()),

    //阶段流程id
    STAGE_PROCESS_ID(PaasStageEnum.STAGE_PROCESS_ID.getAttr(), "enum.customerManagement.attrName.stage_process_id", PaasStageEnum.STAGE_PROCESS_ID.getSaasAttr(), FieldTypeEnum.LONG.getType(), 1, 0, 1, ShowTypeEnum.NONE.getCode(), 9980, 0, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    //阶段id
    STAGE_ID(PaasStageEnum.STAGE_ID.getAttr(), "enum.customerManagement.attrName.attrName.stage_id", PaasStageEnum.STAGE_ID.getSaasAttr(), FieldTypeEnum.LONG.getType(), 1, 0, 1, ShowTypeEnum.NONE.getCode(), 9981, 0, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    //阶段比率
    STAGE_RATIO(PaasStageEnum.STAGE_RATIO.getAttr(),"enum.customerManagement.attrName.attrName.stage_ratio", PaasStageEnum.STAGE_RATIO.getSaasAttr(), FieldTypeEnum.STAGE_RATIO.getType(), ScreenTypeEnum.SCREEN_GROUP.getType(), 0, 0, ShowTypeEnum.ALL.getCode(), 9911, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),

    /**
     * num_62：退回次数
     */
    BACK_NUM(ManagementBaseEnum.BACK_NUM.getAttr(), "enum.customerManagement.attrName.back_num", "backNum", FieldTypeEnum.NUM.getType(), 1, 1, 0, ShowTypeEnum.ALL.getCode(), 9513, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),

    /**
     * text_85：所属公海分组
     */
    PUBLIC_GROUP(ManagementBaseEnum.PUBLIC_GROUP.getAttr(), "enum.customerManagement.attrName.public_group", "publicGroup", FieldTypeEnum.PUBLIC_GROUP.getType(), 1, 1, 0, ShowTypeEnum.ALL.getCode(), 9512, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    /**
     * sysDate1：合同最近签订时间
     */
    CONTRACT_SIGN_DATE(ManagementBaseEnum.CONTRACT_SIGN_DATE.getAttr(), "enum.customerManagement.attrName.contract_sign_date", "contractSignDate", FieldTypeEnum.DATETIME.getType(), 1, 0, 1, ShowTypeEnum.NONE.getCode(), 9511, 0, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    /**
     * sysDate2：机会最近创建时间
     */
    OPPORTUNITY_ADD_DATE(ManagementBaseEnum.OPPORTUNITY_ADD_DATE.getAttr(), "enum.customerManagement.attrName.opportunity_add_date", "opportunityAddDate", FieldTypeEnum.DATETIME.getType(), 1, 0, 1, ShowTypeEnum.NONE.getCode(), 9510, 0, 0, ScreenTypeEnum.SCREEN_OFF.getType()),

    ;
    /**
     * 英文名称
     */
    private String attr;
    /**
     * 中文名称
     */
    private String attrName;
    /**
     * 对应saas中的attr
     */
    private String saasAttr;
    /**
     * 字段类型，详见
     *
     * @see com.xbongbong.paas.enums.FieldTypeEnum
     */
    private Integer fieldType;
    /**
     * 重命名、判重、启用必填等权限
     * 1.重命名+字段权限
     * 2.重命名+字段权限+查重
     * 3.重命名+字段权限+启用、必填
     * 4.重命名+字段权限+查重+启用、必填
     * 注：pro中启用和必填是同一个权限，同时启用或同时关闭
     */
    private Integer setType;
    /**
     * 模板设计阶段字段是否允许编辑
     * 1：允许编辑
     * 0：不允许编辑
     */
    private Integer designEditable;
    /**
     * 字段是否显示在模板设计界面
     * 1：不显示
     * 0：显示
     */
    private Integer editHide;
    /**
     * 字段在各个界面（新建、编辑、列表、详情）的展现形式
     * 详见
     *
     * @see com.xbongbong.saas.enums.ShowTypeEnum
     */
    private Integer showType;
    /**
     * 字段在模板设计界面的排序
     * 建议不要用连续的数字，可以用等差数列，以防以后在两个字段之间加入新字段
     */
    private Integer sort;
    /**
     * 字段在各个界面是否可见(启用)
     * 1：可见
     * 0：不可见
     * 注：字段在具体页面的可见性需要用属性和showType联合判断，在visible=1的情况下判断showType
     */
    private Integer visible;
    /**
     * 字段是否必填
     * 1：必填
     * 0：不必填
     */
    private Integer required;
    /**
     * 筛选类型
     * 1：可筛选
     * 2：不可筛选
     */
    private Integer screenType;

    CustomerManagementEnum(String attr, String attrName, String saasAttr, Integer fieldType, Integer setType, Integer designEditable,
                           Integer editHide, Integer showType, Integer sort, Integer visible, Integer required, Integer screenType) {
        this.attr = attr;
        this.attrName = attrName;
        this.saasAttr = saasAttr;
        this.fieldType = fieldType;
        this.setType = setType;
        this.designEditable = designEditable;
        this.editHide = editHide;
        this.showType = showType;
        this.sort = sort;
        this.visible = visible;
        this.required = required;
        this.screenType = screenType;
    }

    /**
     * 对data内的字段拼上“data.”
     *
     * @param cache
     * @return java.lang.String
     * @author zcp
     * @date 2019/3/1 18:12
     * @version v1.0
     * @since v1.0
     */
    public static String getAttrConnectData(CustomerManagementEnum cache) {
        return "data." + cache.getAttr();
    }

    /**
     * 获取es查询、聚合字段
     * data在库内是json对象，对data字段内某个key做es【精确查询】时，需要在其前拼上“data.”，且【text等类型的】要在后面拼“.keyword”
     *
     * @param cache 当前枚举对象
     * @return java.lang.String 处理后的聚合字段
     * @author zcp
     * @date 2019/2/21 14:59
     * @version v1.0
     * @since v1.0
     */
    public static String getEsAttr4Keyword(CustomerManagementEnum cache) {
        FieldTypeEnum fieldTypeEnum = FieldTypeEnum.getFieldTypeEnum(cache.fieldType);
        //字段类型为text，或者字段在es内的类型时text，则需要在后面拼上“.keyword”
        boolean flag = fieldTypeEnum == FieldTypeEnum.TEXT || "text".equals(fieldTypeEnum.getEsalias());
        if (flag) {
            return "data." + cache.getAttr() + ".keyword";
        }
        return "data." + cache.getAttr();
    }

    /**
     * 根据指标规则枚举获取出数据字典相应字段（主要是客户行业、来源、状态等）
     *
     * @param indicatorRuleEnum 指标规则枚举
     * @return com.xbongbong.saas.enums.dictionary.DictionaryEnum
     * @author zcp
     * @date 2019/5/1 17:26
     * @version v1.0
     * @since v1.0
     */
    public static String getEsAttrByIndicatorRuleEnum(IndicatorRuleEnum indicatorRuleEnum) {
        if (IndicatorRuleEnum.CUSTOMER_INDUSTRY == indicatorRuleEnum) {
            return getEsAttr4Keyword(INDUSTRY);
        } else if (IndicatorRuleEnum.CUSTOMER_SOURCE == indicatorRuleEnum) {
            return getEsAttr4Keyword(SOURCE);
        } else if (IndicatorRuleEnum.CUSTOMER_TYPE == indicatorRuleEnum) {
            return getEsAttr4Keyword(TYPE);
        }
        return "";
    }

    /**
     * 拼接地址字段
     * 库内地址字段的格式为：data对象—address对象—{"province": "", "district":"", "city":"", "address": ""}
     *
     * @param addressEnum
     * @param key         类型，此处传"province"、"district"、"city"
     * @return java.lang.String 处理后的es地址聚合字段
     * @author zcp
     * @date 2019/2/25 14:50
     * @version v1.0
     * @since v1.0
     */
    public static String getAddress4Aggs(CustomerManagementEnum addressEnum, String key) {
        String province = "province";
        String district = "district";
        String city = "city";
        String attr = "data." + addressEnum.getAttr() + ".";
        if (province.equals(key)) {
            return attr + province + ".keyword";
        } else if (district.equals(key)) {
            return attr + district + ".keyword";
        } else if (city.equals(key)) {
            return attr + city + ".keyword";
        }
        return attr + "keyword";
    }

    public static List<JSONObject> getCheckRepeatHead() {
        JSONObject customerName = new JSONObject();
        customerName.put("prop", "name");
        customerName.put("fieldType", NAME.fieldType);
        customerName.put("label", NAME.getAttrName());
        customerName.put("attr", NAME.attr);
        JSONObject mainUser = new JSONObject();
        mainUser.put("prop", "mainUser");
        mainUser.put("fieldType", OWNER_ID.fieldType);
        mainUser.put("label", OWNER_ID.getAttrName());
        mainUser.put("attr", OWNER_ID.attr);
        JSONObject addTime = new JSONObject();
        addTime.put("prop", "addTime");
        addTime.put("fieldType", ADD_TIME.fieldType);
        addTime.put("label", ADD_TIME.getAttrName());
        addTime.put("attr", ADD_TIME.attr);
        JSONObject customerStatus = new JSONObject();
        customerStatus.put("prop", "customerStatus");
        customerStatus.put("fieldType", TYPE.fieldType);
        customerStatus.put("label", TYPE.getAttrName());
        customerStatus.put("attr", TYPE.attr);
        JSONObject position = new JSONObject();
        position.put("prop", "position");
        position.put("fieldType", FieldTypeEnum.TEXT.getType());
        position.put("label", I18nMessageUtil.getMessage(I18nStringConstant.LOCATION));
//        JSONObject formName = new JSONObject();
//        formName.put("prop", "formName");
//        formName.put("fieldType", FieldTypeEnum.TEXT.getType());
//        formName.put("label", I18nMessageUtil.getMessage(I18nStringConstant.FORM_NAME));
        JSONObject isArchived = new JSONObject();
        isArchived.put("prop", "isArchived");
        isArchived.put("fieldType", IS_ARCHIVED.fieldType);
        isArchived.put("label", IS_ARCHIVED.getAttrName());
        isArchived.put("attr", IS_ARCHIVED.attr);
        JSONObject option = new JSONObject();
        option.put("prop", "option");
        option.put("fieldType", FieldTypeEnum.OPTION.getType());
        option.put("label", I18nMessageUtil.getMessage(CommonConstant.OPERATE));
        return Arrays.asList(customerName, mainUser, addTime, customerStatus, position, isArchived, option);
    }

    /**
     * app端详情默认标签显示字段
     *
     * @return List
     * @author GuoJun.HU
     * @date 2019/4/8 19:21
     * @since V1.0
     */
    public static List<Object> getLabelAttrList() {
        return Arrays.asList(TYPE, IS_INDIVIDUAL, SCALE, INDUSTRY, IMPORTANT_DEGREE);
    }

    /**
     * 详情默认摘要
     *
     * @author GuoJun.HU
     * @since V1.0
     * @return List
     * @date 2019/4/8 19:21
     */
    public static List<Object> getSummaryAttrList() {
        return Arrays.asList(OWNER_ID, LAST_CONNECT_TIME);
    }

    /**
     * app端详情默认标题显示字段
     *
     * @return List
     * @author GuoJun.HU
     * @date 2019/4/8 19:21
     * @since V1.0
     */
    public static List<Object> getTitleAttrList() {
        return Collections.singletonList(NAME);
    }

    /**
     * app端详情默认标签显示字段
     * @return List
     * @author xingxing.xiao
     */
    public static List<Object> getLabelAttrListSimple() {
        return Arrays.asList(TYPE);
    }

    /**
     * 详情默认摘要
     * @return List
     * @author xingxing.xiao
     */
    public static List<Object> getSummaryAttrSimpleList() {
        return Arrays.asList(OWNER_ID);
    }

    /**
     * 流程中获取隐藏字段
     *
     * @return
     */
    public static List<CustomerManagementEnum> getDisableField() {
        List<CustomerManagementEnum> customerManagementEnums = new ArrayList<>();
        for (CustomerManagementEnum customerManagementEnum : values()) {
            if (Objects.equals(customerManagementEnum.getShowType(), ShowTypeEnum.NONE.getCode()) || Objects.equals(customerManagementEnum.getEditHide(), 1)
                    || Objects.equals(customerManagementEnum.getFieldType(), FieldTypeEnum.CREATORID.getType()) || Objects.equals(customerManagementEnum.getFieldType(), FieldTypeEnum.ADDTIME.getType())) {
                customerManagementEnums.add(customerManagementEnum);
            }
        }
        return customerManagementEnums;
    }

    /**
     * 把传入的字段（类型为LINK_BUSINESS_SINGLE）的转为其隐藏字段
     * @param attr 字段名
     * @return java.lang.String
     * @author zcp
     * @date 2019/7/4 15:31
     * @since v1.0
     * @version v1.0
     */
    public static String changeToHide4Link(String attr) {
        if (Objects.equals(attr, PARENT.attr)) {
            return PARENT_HIDE.attr;
        }
        // youli.chen 关联销售线索
        if (Objects.equals(attr, CLUE_ID.attr)) {
            return CLUE_NAME_ID.attr;
        }
        return attr;
    }

    /**
     * 将对应attr的枚举返回
     * @param attr
     * @return
     */
    public static CustomerManagementEnum getAttrName(String attr) {
        for (CustomerManagementEnum customerManagementEnum : values()) {
            if (Objects.equals(customerManagementEnum.getAttr(), attr)){
                return customerManagementEnum;
            }
        }
        return null;
    }


    /**
     * 获取统计规则的归属人设置相关字段
     * @return
     */
    public static List<String> getCustomerBelongAttrs() {
        return Arrays.asList(CustomerManagementEnum.CREATOR_ID.getAttr(), CustomerManagementEnum.OWNER_ID.getAttr(), CustomerManagementEnum.COUSERID.getAttr());
    }

    /**
     * 获取销售漏斗的统计规则的统计时间设置相关字段
     * @return
     */
    public static List<String> getCustomerTimeAttrs() {
        return Arrays.asList(CustomerManagementEnum.ADD_TIME.getAttr(), CustomerManagementEnum.UPDATE_TIME.getAttr(), CustomerManagementEnum.LAST_CONNECT_TIME.getAttr());
    }

    public String getAttrName() {
        return I18nMessageUtil.getMessage(attrName);
    }

    public static String getI18nValue(String value) {
        return I18nMessageUtil.getMessage(value);
    }
}
